package com.Offer;

import java.util.Stack;

/*
    面试题30：包含min函数的栈
    定义栈的数据结构，请在该类型中实现一个能够得到栈最小元素的 min 函数。
 */
public class demo30 {


    public static Stack<Integer> stack1 = new Stack();
    public static Stack<Integer> stack2 = new Stack();
    public static void main(String[] args) {

    }

    public static void push(int node){
        stack1.push(node);
        if(stack2.isEmpty()){
            stack2.push(node);
        }else{
            if(stack2.peek() > node){
                stack2.push(node);
            }
        }
    }

    public void pop(){
        if(stack1.pop() == stack2.peek()){
            stack1.pop();
        }
    }

    public int top(){
        return stack1.peek();
    }

    public int min(){
        return stack2.peek();
    }
}
